package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.bean.News;
import com.itheima.mapper.NewsMapper;
import com.itheima.service.NewsService;
import com.itheima.utils.MapperUtils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class NewsServiceImpl implements NewsService {
    @Override
    public PageInfo<News> findByPage(int currentPage, int pageSize) {
        try{
            NewsMapper newsMapper = MapperUtils.getMapper(NewsMapper.class);
            //分页必要操作
            PageHelper.startPage(currentPage, pageSize);
            List<News> newsList=newsMapper.fingAll();
            return  new PageInfo<>(newsList);
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            MapperUtils.close();
        }
        return null;
    }

   /* public PageInfo<News> findByPage(int currentPage, int pageSize) {
        try{
            NewsMapper newsMapper = MapperUtils.getMapper(NewsMapper.class);
            PageHelper.startPage(currentPage, pageSize);
            List<News>newsList=newsMapper.findAll();
            return new PageInfo<>(newsList);

        }catch(Exception e){
            e.printStackTrace();
        }finally {
            MapperUtils.close();
        }
        return null;
    }*/
}
